﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading;

namespace NTimeAuto
{
    /// <summary>
    /// 采用.net4.0，应用于能上网的xp及win7电脑同步互联网时间
    /// 可将本程序加入开机启动
    /// </summary>
    public class Program
    {
        static void Main(string[] args)
        {
            AppDomain.CurrentDomain.AssemblyResolve += CurrentDomain_AssemblyResolve;
            NetTime nt = new NetTime();
            try
            {
                if (UpdateTime.SetDate(nt.getDT()))
                {
                    Console.WriteLine("时间同步成功");
                    Thread.Sleep(1000);
                    // Console.ReadKey();
                }
            }
            catch
            {
                Console.WriteLine("时间同步失败");
                Thread.Sleep(1000);
            }
                
  
               
        }
        private static Assembly CurrentDomain_AssemblyResolve(object sender, ResolveEventArgs e)
        {
            //项目的命名空间为myapp, 嵌入dll资源在libs文件夹下，所以这里用的命名空间为： myapp.lib.
            string _resName = "NTimeAuto.libs." + "Newtonsoft.Json.dll";
            using (var _stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(_resName))
            {
                byte[] _data = new byte[_stream.Length];
                _stream.Read(_data, 0, _data.Length);
                return Assembly.Load(_data);
            }
        }
    }
}
